<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="父节点" prop="contact.id"
                :rules="[
                 ]">
          <SelectTree
                      ref="contact"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/monitor/videodetection/monitorVideoDetectionMain/treeData"
                      :value="inputForm.contact.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.contact.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="用户名" prop="monitorUser"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorUser" placeholder="请填写用户名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="密码" prop="monitorPassword"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorPassword" placeholder="请填写密码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="端口号" prop="monitorIp"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorIp" placeholder="请填写端口号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设备端口" prop="monitorEquipmentIp"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorEquipmentIp" placeholder="请填写设备端口"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="地区" prop="monitorAdress"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorAdress" placeholder="请填写地区"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="ip地址" prop="monitorIpAdress"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorIpAdress" placeholder="请填写ip地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设备" prop="monitorEquipment"
                :rules="[
                 ]">
              <el-input v-model="inputForm.monitorEquipment" placeholder="请填写设备"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          contact: {
            id: ''
          },
          monitorUser: '',
          monitorPassword: '',
          monitorIp: '',
          monitorEquipmentIp: '',
          monitorAdress: '',
          monitorIpAdress: '',
          monitorEquipment: '',
          remarks: ''
        }
      }
    },
    components: {
      SelectTree
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建视频监测右表`
        } else if (method === 'edit') {
          this.title = '修改视频监测右表'
        } else if (method === 'view') {
          this.title = '查看视频监测右表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/monitor/videodetection/monitorVideoDetectionChild/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.monitorVideoDetectionChild)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/monitor/videodetection/monitorVideoDetectionChild/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>